using System;
using System.Collections.Generic;
using System.Text;
using CodeStory.Core.UI;
using CodeStory.Gallery.ObjectBusiness;
using CodeStory.Gallery.ObjectEntity;

namespace CodeStory.Gallery.Portlets
{

	public class GalleryList : Portlet
	{
		protected global::System.Web.UI.WebControls.DataList dlGallery;
		protected global::CodeStory.WebControls.SmartPager pager;

		protected override void OnInit(EventArgs e) {
			Load += new EventHandler(GalleryList_Load);
			pager.PageChanged += new EventHandler(PageChanged);
			base.OnInit(e);
		}

		void PageChanged(object sender, EventArgs e) {
			//throw new Exception("The method or operation is not implemented.");
			BindGallery();
		}

		void GalleryList_Load(object sender, EventArgs e) {
			//throw new Exception("The method or operation is not implemented.");
			if (!IsPostBack) {
				BindGallery();
			}
		}

		private void BindGallery() {
			int pagesize = pager.PageSize;
			int pageindex = pager.CurrentPage  - 1;
			int recordcount = 0;
			IEnumerable<GalleryMainObject> en = null;
			en = GalleryMainBusiness.ListPage(pagesize, pageindex,out recordcount);
			if (en == null) return;
			pager.RecordCount = recordcount;
			dlGallery.DataSource = en;
			dlGallery.DataBind();
		}
	}
}
